from django.db import models
from django.db.models import permalink

class Country(models.Model):
    name = models.CharField(maxlength=200, unique=True)
    added = models.DateField(auto_now_add=True)
    
    class Meta:
        verbose_name_plural = "Countries"
        
    class Admin:
        ordering   =       ('name',)

    def __str__(self): return self.name
        
class City(models.Model):
    added = models.DateField(auto_now_add=True)
    name = models.CharField(maxlength=200)
    country = models.ForeignKey(Country)
    maps_level = models.IntegerField(default=11)
    satelite_maps = models.BooleanField(default=True, help_text="Do you want to use a satelite image on google maps")
    latitude = models.CharField(maxlength=10, null=True, blank=True)
    longitude = models.CharField(maxlength=10, null=True, blank=True)    

    class Meta:
        verbose_name_plural  = "Cities"
        unique_together = (('name', 'latitude', 'longitude'), )
        
    class Admin:
        list_filter     = ('country',)
        ordering        = ('name',)
        fields = (
            ("Required Information", {'fields':('name', 'country')}),
            ("Geomap Information", {'fields':('latitude', 'longitude', 'satelite_maps', 'maps_level')}),
        )
        js=['/static/js/prototype.js', '/static/js/travel/admin/city.js' ]
        
    def __str__(self): return "%s, %s" % (self.name, self.country)
        
class Destination(models.Model):
    added = models.DateField(auto_now_add=True)
    city = models.ForeignKey(City)
    arrival = models.DateField()
    departure = models.DateField(null=True, blank=True)

    class Meta:
        get_latest_by = 'arrival'

    class Admin:
        list_display        =       ('city', 'arrival', 'departure')
        ordering           =       ('-arrival',)
        search_fields    =       ('city' )
        date_hierarchy =       'arrival'

    def __str__(self): return "%s" % (self.city)
    def get_absolute_url(self): return "/travel/%d" % (self.id)


        
# Create your models here.
